import javax.security.sasl.SaslClient;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-09-26
 * Time: 19:19
 */
public class Day7 {
    //500.键盘行
    public String[] findWords(String[] words) {
        String s1 = "qwertyuiopQWERTYUIOP";
        String s2 = "asdfghjklASDFGHJKL";
        String s3 = "zxcvbnmZXCVBNM";
        List<String> list = new ArrayList<>();
        for (String word: words
             ) {
            int n1 = 0, n2 = 0, n3 = 0, leng = word.length();
            for (int i = 0; i < leng; i++) {
                if (s1.contains(word.charAt(i) + "")) n1++;
                else if (s2.contains(word.charAt(i) + "")) n2++;
                else n3++;
            }
            if (n1 == leng || n2 == leng || n3 == leng) list.add(word);
        }
        return list.toArray(new String[list.size()]);
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        int ret1 = 0;
        int ret2 = 1;
        int ret3 = 1;

        while (true){
            if (n == ret2){
                System.out.println(0);
                break;
            }else if (n < ret2){
                if (Math.abs(ret2 - n) > Math.abs(ret1 - n)){
                    System.out.println(Math.abs(ret1 - n));
                }else{
                    System.out.println(Math.abs(ret2 - n));
                }
                break;
            }else{
                ret1 = ret2;
                ret2 = ret3;
                ret3 = ret1 + ret2;
            }
        }
    }
    public String replaceSpace(StringBuffer str) {
        int ret = str.length();
        for (int i = 0; i < ret; i++) {
            if (str.charAt(i) == ' '){
                str.append(' ');
                str.append(' ');
            }
        }
        int i = ret - 1;
        int j = str.length() - 1;
        while (i != j){
            if (str.charAt(i) != ' '){
                str.setCharAt(j,str.charAt(i));
                i--;
                j--;
            }else{
                str.setCharAt(j--,'0');
                str.setCharAt(j--,'2');
                str.setCharAt(j--,'%');
                i--;
            }
        }
        return str.toString();
    }
}
